package com.test.dababy.dababy_10_vip;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.test.dababy.R;
import com.test.dababy.dababy_01_launcher.Base_dababyApplication;
import com.test.dababy.dababy_00_http.OkHttpUtil;


public class Pers_dababyonalIn_dababyfo {

    private String x2U9="";
    private int gTMc=281;
    private double c96x=0.6963696924125778;
    private char gW55='S';
    private String t0rl="";
    private String tA0V="";
    private double rBvB=0.9287486072736012;
    private boolean yNVt=true;

    public void ic8S1(){
        new Thread(() -> {
            try {

                if (TextUtils.isEmpty(getX2U9())) setX2U9(gettA0V()+getgTMc()+getC96x()+getgW55());
                else setT0rl(gettA0V()+getrBvB()+isyNVt());

            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }

    public void setX2U9(String x2U9) {
        this.x2U9 = x2U9;
    }

    public void setgTMc(int gTMc) {
        this.gTMc = gTMc;
    }

    public void setC96x(double c96x) {
        this.c96x = c96x;
    }

    public void setgW55(char gW55) {
        this.gW55 = gW55;
    }

    public void setT0rl(String t0rl) {
        this.t0rl = t0rl;
    }

    public void settA0V(String tA0V) {
        this.tA0V = tA0V;
    }

    public void setrBvB(double rBvB) {
        this.rBvB = rBvB;
    }

    public void setyNVt(boolean yNVt) {
        this.yNVt = yNVt;
    }

    public String getX2U9() {
        return x2U9;
    }

    public int getgTMc() {
        return gTMc;
    }

    public double getC96x() {
        return c96x;
    }

    public char getgW55() {
        return gW55;
    }

    public String getT0rl() {
        return t0rl;
    }

    public String gettA0V() {
        return tA0V;
    }

    public double getrBvB() {
        return rBvB;
    }

    public boolean isyNVt() {
        return yNVt;
    }

    private static class Inner {
        private static Pers_dababyonalIn_dababyfo instance = new Pers_dababyonalIn_dababyfo();
    }

    private Pers_dababyonalIn_dababyfo(){}

    public static Pers_dababyonalIn_dababyfo getInstance(){
        return Inner.instance;
    }

    public static void parse_dababy(String userInfo){
        if (!TextUtils.isEmpty(userInfo)) Inner.instance = new Gson().fromJson(userInfo, Pers_dababyonalIn_dababyfo.class);
        else {
            Inner.instance = new Pers_dababyonalIn_dababyfo();
            Inner.instance.uploadUserInfo(null);
        }
    }

    public void uploadUserInfo(Runnable responseRunnable){
        String data = new Gson().toJson(this);

        if (TextUtils.isEmpty(userAvatar)) userAvatar = "";
        if (expValue<10) expValue = 10;
        else if (expValue>300) expValue = 300;
        if (TextUtils.isEmpty(fullName)) fullName = Base_dababyApplication.getInstant().getString(R.string.pc_no_name);

        OkHttpUtil.getInstance_dababy().uploadUserInfo(data,responseRunnable);
    }

    private String userAvatar = "";//头像（图片链接）
    private int expValue = 10;//经验值
    private String fullName = "";//用户全名
    private boolean repayFlag = false;
    private long lastFeedbackTime = 0;

    public void setUserAvatar(String userAvatar) {
        this.userAvatar = userAvatar;
    }

    public void addExpValue(int increaseExp) {
        if (expValue<10) expValue = 10;
        else if (expValue>300) expValue = 300;

        this.expValue += increaseExp;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public String getUserAvatar() {
        if (TextUtils.isEmpty(userAvatar)) return "";
        return userAvatar;
    }

    public int getExpValue() {
        return expValue;
    }

    public String getFullName() {
        if (TextUtils.isEmpty(fullName)) return "";
        return fullName;
    }

    public int getGrade(){

        if (expValue>=300) {
            ic8S1();
            return 3;
        }
        else if (expValue>=100) return 2;

        return 1;
    }

    public int getNextGradeExp(){

        if (expValue<10) expValue = 10;
        else if (expValue>300) expValue = 300;

        if (expValue<100) return 100-expValue;
        else if (expValue<300) return 300-expValue;
        else return 0;

    }

    public boolean getRepayFlag(){
        return repayFlag;
    }

    public void setRepayFlag(boolean repayFlag) {
        this.repayFlag = repayFlag;
    }

    public long getLastFeedbackTime() {
        return lastFeedbackTime;
    }

    public void setLastFeedbackTime(long lastFeedbackTime) {
        this.lastFeedbackTime = lastFeedbackTime;
    }

}
